package com.example.entity.header;

import com.example.constant.MessageConstant;

import io.netty.buffer.ByteBuf;

public class Header {
	private final byte startSign = MessageConstant.HEADER_START_SIGN;
	private char contextLength;
	private int UControlField;

	public final char getContextLength() {
		return contextLength;
	}

	public final void setContextLength(int contextLength) {
		this.contextLength = (char) contextLength;
	}

	public final int getUControlField() {
		return UControlField;
	}

	public final void setUControlField(int uControlField) {
		UControlField = uControlField;
	}

	public final byte getStartSign() {
		return startSign;
	}

	@Override
	public String toString() {
		return "Header [startSign=" + startSign + ", contextLength=" + contextLength + ", UControlField="
				+ UControlField + "]";
	}

	@Override
	public boolean equals(Object obj) {
		System.out.println("调用头部equal");
		if (obj == null) {
			System.out.println("header空");
			return false;
		}
		if (!(obj instanceof Header)) {
			System.out.println("header类型错");
			return false;
		}
		Header other = (Header) obj;
		if (UControlField != other.UControlField) {
			System.out.println("header 1");
			return false;
		}
		if (contextLength != other.contextLength) {
			System.out.println("header 2");
			return false;
		}
		if (startSign != other.startSign) {
			System.out.println("header 3");
			return false;
		}
		return true;
	}

	public void write(ByteBuf buf) {
		buf.writeByte(startSign);
		buf.writeChar(contextLength);
		buf.writeInt(UControlField);
	}

}
